var index = 0;
Page({
  data:{
    name:"",
    tel:"",
    addreValue:0,
    region: [],
    // addreRange:['　　　　　　　　　　','长沙市芙蓉区','长沙市天心区','长沙市雨花区','长沙市开福区','长沙市岳麓区','长沙市长沙县'],
    door:"",
    areaValue:0,
    // areaRange:['　　','60以下','60-90','90-110','110-130','130-140','140-150','150-160','160-170','170-180','180以上']
  },
  bindRegionChange: function (e) {
    console.log(e.detail.value)
    console.log(e.detail.code)
    this.setData({
      region: e.detail.value
    })
  },
  bindNameChange:function(e){
    this.setData({
      name:e.detail.value
    })
  },
  bindDoorChange:function(e){
    this.setData({
      door:e.detail.value
    })
  },
  bindTelChange:function(e){
    this.setData({
    tel:e.detail.value
    })
  },
  formSubmit: function(e) {
    var warn ="";
    var that = this;
    var flag = false;
    if(e.detail.value.name==""){
      warn = "请填写您的姓名！";
    }else if(e.detail.value.tel==""){
      warn = "请填写您的手机号！";
    }else if(!(/^1(3|4|5|7|8)\d{9}$/.test(e.detail.value.tel))){
      warn = "手机号格式不正确";
    }else if(e.detail.value.region==''){//e.detail.value.addre
      warn = "请选择您的所在区域";
    }else if(e.detail.value.door==""){
      warn = "请输入您的具体地址";
    }else{
      flag=true;
      console.log('form发生了submit事件，携带数据为：', e.detail.value)

      let pages = getCurrentPages();  
      let prevPage = pages[ pages.length - 2 ];

      prevPage.setData({  // 将我们想要传递的参数在这里直接setData。上个页面就会执行这里的操作。
            name:e.currentTarget.dataset.name,
            region: e.currentTarget.dataset.region,
            door: e.currentTarget.dataset.door,
            tel: e.currentTarget.dataset.tel,
            flag:this.flag
      })
      wx.navigateBack({
        delta: 1,
      })
      //  wx.redirectTo({
      //   // url: '../chooseAddre/chooseAddre?tel='+e.detail.value.tel+"&addre="+that.data.addreRange[e.detail.value.addre]+"&door="+e.detail.value.door+"&name="+e.detail.value.name+"&area="+that.data.areaRange[e.detail.value.area]+"&flag="+flag+"&areavalue="+e.detail.value.area+"&addrevalue="+e.detail.value.addre+"&door="+e.detail.value.door
      //   url: '../chooseAddre/chooseAddre?tel='+e.detail.value.tel+"&region="+e.detail.value.region+"&door="+e.detail.value.door+"&name="+e.detail.value.name+"&flag="+flag
      //   //？后面跟的是需要传递到下一个页面的参数

      // }); 
      wx.request({
        url: 'http://82.157.94.115:2005/address',
        method: 'POST',
        header: {
          "Content-Type": "application/x-www-form-urlencoded"
        },
        data: {
          name:that.data.name,
          tel:that.data.tel,
          region:that.data.region,
          door:that.data.door,
        },
        success:function(){
          console.log('成功')
        }
      })
      
         console.log("传过去的地址下标是多少？"+e.detail.value.region)

    }
    if(flag==false){
      wx.showModal({
      title: '提示',
      content:warn
    })
    }
    
  },
  
  })